from syslogd.configuration.Configuration import Configuration
from syslogd.configuration.ConfReader import ConfReader
from syslogd.configuration.ConfWriter import ConfWriter
from syslogd.configuration.ConfParser import ConfParser
from syslogd.status.ServiceController import ServiceController
from syslogd.status.Status import Status
from syslogd.log.Filter import Filter, Filters
from syslogd.log.Stats import Stats
from syslogd.Utils import Utils
import time



fifo = Utils.makeFifo()
Status.setStatus(ServiceController.sudoStopSyslogd())

cr = ConfReader(Configuration.getSyslogdConfigurationPath())
cr.read() 

confLines = ConfParser.createConfObjects(cr.getList())
ConfWriter.writeConf(Status, confLines)
  
filters = Filters()
filters.addFilter(Filter([".*in.*","s"],20,4))
f = Filter([".*s.*","asa"],20,1)
filters.addFilter(f)
filters.addFilter(Filter([".*rsyslog.*"],20,5))
filters.removeFilter(f)

stats = Stats(filters)

while 1:

    line = fifo.readline()
    if line != '':
        filters.determineLog(line.strip())
    else:
        print stats.getStats()
        time.sleep(10)